﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using InfoSource.Data;
using System.Web.Script.Serialization;

namespace InfoSource.Models
{
	public class ManageDoNotMarketListViewModel
	{
		#region Properties ======================================================================
		private List<Do_Not_Market_List> _ZipCodes;
		public List<Do_Not_Market_List> ZipCodes
		{
			get
			{
				if (_ZipCodes == null)
					SetZipCodes();

				return _ZipCodes;
			}
		}
		
		public string SerializedZipCodes 
		{ 
			get 
			{
				return new JavaScriptSerializer().Serialize(
					ZipCodes.ToDictionary(
						zip => zip.Zip.ToString()
						, zip => new 
									{ 
										City = zip.colorado_zipcodes.FirstOrDefault().city
										, Lat = zip.colorado_zipcodes.FirstOrDefault().Latitude
										, Long = zip.colorado_zipcodes.FirstOrDefault().Longitude 
									}
					)
				);
			} 
		}

		public List<colorado_zipcode> RemainingZipCodes
		{
			get
			{
				return new InfoSourceDB()
					.colorado_zipcodes
					.Where(remaining_zip => 
						!ZipCodes.Select(zip => zip.Zip).Contains(remaining_zip.zip))
					.ToList();
			}
		}

		#endregion ==============================================================================

		#region Constructor =====================================================================

		public ManageDoNotMarketListViewModel()
		{
		}

		#endregion ==============================================================================

		#region Methods =========================================================================

		private void SetZipCodes()
		{
			_ZipCodes = new InfoSourceDB().Do_Not_Market_Lists.Select(zip => zip).ToList();
		}

		#endregion ==============================================================================
	}
}
